<?php require('connections/con_gl.php'); ?>
<?php
cekAkses($_SESSION[akses],"L-5");
mysql_select_db($database_con_gl, $con_gl);
$query_getaktiva1 = "SELECT gl_akun.id, gl_akun.akun FROM gl_akun WHERE gl_akun.aruskas=1";
$getaktiva1 = mysql_query($query_getaktiva1, $con_gl) or die(mysql_error());
$row_getaktiva1 = mysql_fetch_assoc($getaktiva1);
$totalRows_getaktiva1 = mysql_num_rows($getaktiva1);

mysql_select_db($database_con_gl, $con_gl);
$query_getaktiva2 = "SELECT gl_akun.id, gl_akun.akun FROM gl_akun WHERE gl_akun.aruskas=2";
$getaktiva2 = mysql_query($query_getaktiva2, $con_gl) or die(mysql_error());
$row_getaktiva2 = mysql_fetch_assoc($getaktiva2);
$totalRows_getaktiva2 = mysql_num_rows($getaktiva2);

mysql_select_db($database_con_gl, $con_gl);
$query_getinv = "SELECT gl_akun.id, gl_akun.akun FROM gl_akun WHERE gl_akun.aruskas=3";
$getinv = mysql_query($query_getinv, $con_gl) or die(mysql_error());
$row_getinv = mysql_fetch_assoc($getinv);
$totalRows_getinv = mysql_num_rows($getinv);

mysql_select_db($database_con_gl, $con_gl);
$query_getdana = "SELECT gl_akun.id, gl_akun.akun FROM gl_akun WHERE gl_akun.aruskas=4";
$getdana = mysql_query($query_getdana, $con_gl) or die(mysql_error());
$row_getdana = mysql_fetch_assoc($getdana);
$totalRows_getdana = mysql_num_rows($getdana);
?>
<link href="css/ui.datepicker.css" type="text/css" rel="stylesheet" />
<!--<script language="JavaScript" src="js/FusionCharts.js"></script>
<script type="text/javascript" src="calendar/jquery-1.2.3.js"></script>-->
<script type="text/javascript" src="js/ui.datepicker.js"></script>
<script type="text/javascript">
<!--
$(function()
      {
        $('.calendar').datepicker({
            appendText : "",
            dateFormat : 'yy/mm/dd'
          });
      });
</script>
<h1>ARUS KAS</h1> <?php if(isset($_POST[Search]) AND $_POST[Mulai]<>'Mulai...' AND $_POST[Sampai]<>'Sampai...') { ?><?php tanggal($_POST[Mulai],"tampilkan");?> - <?php tanggal($_POST[Sampai],"tampilkan");?><?php } ?>
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0"> 
  <tr valign="top" class="hide">
    <td align="right"><form id="search" name="search" method="post" action="">
      <label>
      <input name="Mulai" type="text" class="calendar" id="Mulai" value="<?php if(empty($_POST[Mulai])) echo "Mulai...";else echo $_POST[Mulai];?>"onblur="if(this.value=='') this.value='Mulai...';" onfocus="if(this.value=='Mulai...') this.value='';" />
        </label>
      s/d
  <label>
  <input name="Sampai" type="text" class="calendar" id="Sampai" value="<?php if(empty($_POST[Sampai])) echo "Sampai...";else echo $_POST[Sampai];?>"onblur="if(this.value=='') this.value='Sampai...';" onfocus="if(this.value=='Sampai...') this.value='';" />
  </label>
  <label>
  <input name="Search" type="submit" id="Search" value="Tampilkan" />
  </label>
    </form></td>
  </tr>
  <?php if(isset($_POST['Search'])) { $per1 = $_POST[tahun]."/".$_POST[bulan1]; $per2 = $_POST[tahun]."/".$_POST[bulan2];?>
  <div id="box-exportdata"><a href="javascript:window.print();"><img src="images/_print.png" border="0" /></a></div>
  <tr>
    <td ><table width="100%" border="0" cellspacing="0" cellpadding="5" class="datatable">
        <tr>
          <td width="25%" align="center"><strong>Arus Kas Kegiatan Operasi </strong> </td>
          <td width="38%">&nbsp;</td>
          <td width="21%">&nbsp;</td>
          <td width="16%">&nbsp;</td>
        </tr>
            <tr valign="top">
              <td align="right" bgcolor="#FFFFFF"><strong>Aktiva Lancar :</strong> </td>
              <td align="left" bgcolor="#FFFFFF">&nbsp;</td>
              <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
              <td bgcolor="#FFFFFF">&nbsp;</td>
            </tr>
            <?php $tot1 = 0; do { ?>
			<?php
			mysql_select_db($database_con_gl, $con_gl);
$query_gettotal = "SELECT sum(gl_trans.total), gl_trans.akun, gl_rtrans.no_ref FROM gl_rtrans, gl_trans WHERE gl_trans.pos='D' AND gl_trans.akun='$row_getaktiva1[id]' AND gl_trans.no_ref=gl_rtrans.no_ref";
if(!strstr($_SESSION[akses],'A-1-4')) {
	$query_gettotal .= " AND gl_rtrans.gudang='$_SESSION[lokasi]'";
}
if($_POST[Mulai]<>'Mulai...' AND $_POST[Sampai]<>'Sampai...') { 
$query_gettotal .=" AND gl_rtrans.tgl between '$_POST[Mulai]' AND '$_POST[Sampai]'";
}
$query_gettotal .=" GROUP by gl_trans.akun";
$gettotal = mysql_query($query_gettotal, $con_gl) or die(mysql_error());
$row_gettotal = mysql_fetch_assoc($gettotal);
$totalRows_gettotal = mysql_num_rows($gettotal);

mysql_select_db($database_con_gl, $con_gl);
$query_gettotal2 = "SELECT sum(gl_trans.total), gl_trans.akun, gl_rtrans.no_ref FROM gl_rtrans, gl_trans WHERE gl_trans.pos='K' AND gl_trans.akun='$row_getaktiva1[id]' AND gl_trans.no_ref=gl_rtrans.no_ref";
if(!strstr($_SESSION[akses],'A-1-4')) {
	$query_gettotal2 .= " AND gl_rtrans.gudang='$_SESSION[lokasi]'";
}
if($_POST[Mulai]<>'Mulai...' AND $_POST[Sampai]<>'Sampai...') { 
$query_gettotal2 .=" AND gl_rtrans.tgl between '$_POST[Mulai]' AND '$_POST[Sampai]'";
}
$query_gettotal2 .=" GROUP by gl_trans.akun";
$gettotal2 = mysql_query($query_gettotal2, $con_gl) or die(mysql_error());
$row_gettotal2 = mysql_fetch_assoc($gettotal2);
$totalRows_gettotal2 = mysql_num_rows($gettotal2);
$nil = $row_gettotal['sum(gl_trans.total)']-$row_gettotal2['sum(gl_trans.total)'];
			?>
              <tr valign="top">
                <td bgcolor="#FFFFFF">&nbsp;</td>
                <td align="left" bgcolor="#FFFFFF"><?php echo $row_getaktiva1['akun']; ?></td>
                <td align="right" bgcolor="#FFFFFF" style="border-bottom:dotted 1px #1C3554;"><?php if($nil >=0) { echo number_format($nil,0,',','.').",-";}else{ echo "( ".number_format(str_replace("-","",$nil),0,',','.').",-"." )";} $tot1 += $nil;?></td>
                <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
              </tr>
              <?php } while ($row_getaktiva1 = mysql_fetch_assoc($getaktiva1)); ?>
            <tr>
              <td bgcolor="#FFFFFF">&nbsp;</td>
              <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
              <td align="right" bgcolor="#FFFFFF"><span style="font-weight: bold">Total :</span></td>
              <td align="right" bgcolor="#EEEEEE" style="border-bottom:dotted 1px #1C3554;"><?php if($tot1 >=0) { echo number_format($tot1,0,',','.').",-";}else{ echo "( ".number_format(str_replace("-","",$tot1),0,',','.').",-"." )";}?></td>
            </tr>
            <tr valign="top">
              <td align="right" bgcolor="#FFFFFF"><strong>Kewajiban Lancar :</strong> </td>
              <td align="left" bgcolor="#FFFFFF">&nbsp;</td>
              <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
              <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
            </tr>
            <?php $tot2 = 0; do { ?>
			<?php
			mysql_select_db($database_con_gl, $con_gl);
$query_gettotal = "SELECT sum(gl_trans.total), gl_trans.akun, gl_rtrans.no_ref FROM gl_rtrans, gl_trans WHERE gl_trans.pos='D' AND gl_trans.akun='$row_getaktiva2[id]' AND gl_trans.no_ref=gl_rtrans.no_ref";
if(!strstr($_SESSION[akses],'A-1-4')) {
	$query_data .= " AND gl_rtrans.gudang='$_SESSION[lokasi]'";
}
if($_POST[Mulai]<>'Mulai...' AND $_POST[Sampai]<>'Sampai...') { 
$query_gettotal .=" AND gl_rtrans.tgl between '$_POST[Mulai]' AND '$_POST[Sampai]'";
}
$query_gettotal .=" GROUP by gl_trans.akun";
$gettotal = mysql_query($query_gettotal, $con_gl) or die(mysql_error());
$row_gettotal = mysql_fetch_assoc($gettotal);
$totalRows_gettotal = mysql_num_rows($gettotal);

mysql_select_db($database_con_gl, $con_gl);
$query_gettotal2 = "SELECT sum(gl_trans.total), gl_trans.akun, gl_rtrans.no_ref FROM gl_rtrans, gl_trans WHERE gl_trans.pos='K' AND gl_trans.akun='$row_getaktiva2[id]' AND gl_trans.no_ref=gl_rtrans.no_ref";
if(!strstr($_SESSION[akses],'A-1-4')) {
	$query_data .= " AND gl_rtrans.gudang='$_SESSION[lokasi]'";
}
if($_POST[Mulai]<>'Mulai...' AND $_POST[Sampai]<>'Sampai...') { 
$query_gettotal2 .=" AND gl_rtrans.tgl between '$_POST[Mulai]' AND '$_POST[Sampai]'";
}
$query_gettotal2 .=" GROUP by gl_trans.akun";
$gettotal2 = mysql_query($query_gettotal2, $con_gl) or die(mysql_error());
$row_gettotal2 = mysql_fetch_assoc($gettotal2);
$totalRows_gettotal2 = mysql_num_rows($gettotal2);

$nil2 = $row_gettotal['sum(gl_trans.total)']-$row_gettotal2['sum(gl_trans.total)'];
			?>
              <tr valign="top">
                <td bgcolor="#FFFFFF">&nbsp;</td>
                <td align="left" bgcolor="#FFFFFF"><?php echo $row_getaktiva2['akun']; ?></td>
                <td align="right" bgcolor="#FFFFFF" style="border-bottom:dotted 1px #1C3554;"><?php if($nil2 >=0) { echo number_format($nil2,0,',','.').",-";}else{ echo "( ".number_format(str_replace("-","",$nil2),0,',','.').",-"." )";} $tot2 += $nil2;?></td>
                <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
              </tr>
              <?php } while ($row_getaktiva2 = mysql_fetch_assoc($getaktiva2)); ?>
        <tr>
          <td bgcolor="#FFFFFF">&nbsp;</td>
          <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
          <td align="right" bgcolor="#FFFFFF"><span style="font-weight: bold">Total :</span></td>
          <td align="right" bgcolor="#EEEEEE" style="border-bottom:dotted 1px #1C3554;"><?php if($tot2 >=0) { echo number_format($tot2,0,',','.').",-";}else{ echo "( ".number_format(str_replace("-","",$tot2),0,',','.').",-"." )";}?></td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">&nbsp;</td>
          <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
          <td align="right" bgcolor="#FFFFFF"><span style="font-weight: bold">Total Arus Kas Operasi :</span></td>
          <td align="right" bgcolor="#EEEEEE" style="border-bottom:dotted 1px #1C3554;"><?php $totopr = $tot1+$tot2;if($totopr >=0) { echo number_format($totopr,0,',','.').",-";}else{ echo "( ".number_format(str_replace("-","",$totopr),0,',','.').",-"." )";}?></td>
        </tr>
        <tr>
          <td align="center"><strong>Arus Kas Investasi </strong> </td>
          <td align="center">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <?php $tot3 = 0; do { ?>
		<?php
			mysql_select_db($database_con_gl, $con_gl);
$query_gettotal = "SELECT sum(gl_trans.total), gl_trans.akun, gl_rtrans.no_ref FROM gl_rtrans, gl_trans WHERE gl_trans.pos='D' AND gl_trans.akun='$row_getinv[id]' AND gl_trans.no_ref=gl_rtrans.no_ref";
if(!strstr($_SESSION[akses],'A-1-4')) {
	$query_gettotal .= " AND gl_rtrans.gudang='$_SESSION[lokasi]'";
}
if($_POST[Mulai]<>'Mulai...' AND $_POST[Sampai]<>'Sampai...') { 
$query_gettotal .=" AND gl_rtrans.tgl between '$_POST[Mulai]' AND '$_POST[Sampai]'";
}
$query_gettotal .=" GROUP by gl_trans.akun";
$gettotal = mysql_query($query_gettotal, $con_gl) or die(mysql_error());
$row_gettotal = mysql_fetch_assoc($gettotal);
$totalRows_gettotal = mysql_num_rows($gettotal);

mysql_select_db($database_con_gl, $con_gl);
$query_gettotal2 = "SELECT sum(gl_trans.total), gl_trans.akun, gl_rtrans.no_ref FROM gl_rtrans, gl_trans WHERE gl_trans.pos='K' AND gl_trans.akun='$row_getinv[id]' AND gl_trans.no_ref=gl_rtrans.no_ref";
if(!strstr($_SESSION[akses],'A-1-4')) {
	$query_gettotal2 .= " AND gl_rtrans.gudang='$_SESSION[lokasi]'";
}
if($_POST[Mulai]<>'Mulai...' AND $_POST[Sampai]<>'Sampai...') { 
$query_gettotal2 .=" AND gl_rtrans.tgl between '$_POST[Mulai]' AND '$_POST[Sampai]'";
}
$query_gettotal2 .=" GROUP by gl_trans.akun";
$gettotal2 = mysql_query($query_gettotal2, $con_gl) or die(mysql_error());
$row_gettotal2 = mysql_fetch_assoc($gettotal2);
$totalRows_gettotal2 = mysql_num_rows($gettotal2);

$nil3 = $row_gettotal['sum(gl_trans.total)']-$row_gettotal2['sum(gl_trans.total)'];
			?>
          <tr valign="top">
            <td bgcolor="#FFFFFF">&nbsp;</td>
            <td align="left" bgcolor="#FFFFFF"><?php echo $row_getinv['akun']; ?></td>
            <td align="right" bgcolor="#FFFFFF" style="border-bottom:dotted 1px #1C3554;"><?php if($nil3 >=0) { echo number_format($nil3,0,',','.').",-";}else{ echo "( ".number_format(str_replace("-","",$nil3),0,',','.').",-"." )";} $tot3 += $nil3;?></td>
            <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <?php } while ($row_getinv = mysql_fetch_assoc($getinv)); ?>
        <tr>
          <td bgcolor="#FFFFFF">&nbsp;</td>
          <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
          <td align="right" bgcolor="#FFFFFF"><span style="font-weight: bold">Total Arus Kas Investasi:</span></td>
          <td align="right" bgcolor="#EEEEEE" style="border-bottom:dotted 1px #1C3554;"><?php if($tot3 >=0) { echo number_format($tot3,0,',','.').",-";}else{ echo "( ".number_format(str_replace("-","",$tot3),0,',','.').",-"." )";}?></td>
        </tr>
        <tr>
          <td align="center"><strong>Arus Kas Pendanaan </strong></td>
          <td align="center">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <?php $tot4=0; do { ?>
		<?php
			mysql_select_db($database_con_gl, $con_gl);
$query_gettotal = "SELECT sum(gl_trans.total), gl_trans.akun, gl_rtrans.no_ref FROM gl_rtrans, gl_trans WHERE gl_trans.pos='D' AND gl_trans.akun='$row_getdana[id]' AND gl_trans.no_ref=gl_rtrans.no_ref";
if(!strstr($_SESSION[akses],'A-1-4')) {
	$query_gettotal .= " AND gl_rtrans.gudang='$_SESSION[lokasi]'";
}
if($_POST[Mulai]<>'Mulai...' AND $_POST[Sampai]<>'Sampai...') { 
$query_gettotal .=" AND gl_rtrans.tgl between '$_POST[Mulai]' AND '$_POST[Sampai]'";
}
$query_gettotal .=" GROUP by gl_trans.akun";
$gettotal = mysql_query($query_gettotal, $con_gl) or die(mysql_error());
$row_gettotal = mysql_fetch_assoc($gettotal);
$totalRows_gettotal = mysql_num_rows($gettotal);

mysql_select_db($database_con_gl, $con_gl);
$query_gettotal2 = "SELECT sum(gl_trans.total), gl_trans.akun, gl_rtrans.no_ref FROM gl_rtrans, gl_trans WHERE gl_trans.pos='D' AND gl_trans.akun='$row_getdana[id]' AND gl_trans.no_ref=gl_rtrans.no_ref";
if(!strstr($_SESSION[akses],'A-1-4')) {
	$query_gettotal2 .= " AND gl_rtrans.gudang='$_SESSION[lokasi]'";
}
if($_POST[Mulai]<>'Mulai...' AND $_POST[Sampai]<>'Sampai...') { 
$query_gettotal2 .=" AND gl_rtrans.tgl between '$_POST[Mulai]' AND '$_POST[Sampai]'";
}
$query_gettotal2 .=" GROUP by gl_trans.akun";
$gettotal2 = mysql_query($query_gettotal2, $con_gl) or die(mysql_error());
$row_gettotal2 = mysql_fetch_assoc($gettotal2);
$totalRows_gettotal2 = mysql_num_rows($gettotal2);

$nil4 = $row_gettotal['sum(gl_trans.total)']-$row_gettotal2['sum(gl_trans.total)'];
			?>
          <tr valign="top">
            <td bgcolor="#FFFFFF">&nbsp;</td>
            <td align="left" bgcolor="#FFFFFF"><?php echo $row_getdana['akun']; ?></td>
            <td align="right" bgcolor="#FFFFFF" style="border-bottom:dotted 1px #1C3554;"><?php if($nil4 >=0) { echo number_format($nil4,0,',','.').",-";}else{ echo "( ".number_format(str_replace("-","",$nil4),0,',','.').",-"." )";} $tot4 += $nil4;?></td>
            <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <?php } while ($row_getdana = mysql_fetch_assoc($getdana)); ?>
        <tr>
          <td bgcolor="#FFFFFF">&nbsp;</td>
          <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
          <td align="right" bgcolor="#FFFFFF"><span style="font-weight: bold">Total Arus Kas Pendanaan:</span></td>
          <td align="right" bgcolor="#EEEEEE" style="border-bottom:dotted 1px #1C3554;"><?php if($tot4 >=0) { echo number_format($tot4,0,',','.').",-";}else{ echo "( ".number_format(str_replace("-","",$tot4),0,',','.').",-"." )";}?></td>
        </tr>
            </table></td>
  </tr>
  <?php } ?>
</table>